package com.cqfae.deploycentral.app.web.enums;

import com.cqfae.deploycentral.app.base.BaseConstantCode;

public enum DeployPercentEnum {

    DEPLOY_PERCENT_GIT_FAIL(BaseConstantCode.JENKINS_STATUS_GIT_FAIL, 10),
    DEPLOY_PERCENT_GIT_OK(BaseConstantCode.JENKINS_STATUS_GIT_OK, 20),
    DEPLOY_PERCENT_BUILD_FAIL(BaseConstantCode.JENKINS_STATUS_BUILD_FAIL, 30),
    DEPLOY_PERCENT_BUILD_OK(BaseConstantCode.JENKINS_STATUS_BUILD_OK, 40),
    DEPLOY_PERCENT_INPUT_FAIL(BaseConstantCode.JENKINS_STATUS_INPUT_FAIL, 50),
    DEPLOY_PERCENT_INPUT_OK(BaseConstantCode.JENKINS_STATUS_INPUT_OK, 60),
    DEPLOY_PERCENT_OUTPUT_FAIL(BaseConstantCode.JENKINS_STATUS_OUTPUT_FAIL, 70),
    DEPLOY_PERCENT_OUTPUT_OK(BaseConstantCode.JENKINS_STATUS_OUTPUT_OK, 80),
    DEPLOY_PERCENT_DEPLOY_FAIL(BaseConstantCode.JENKINS_STATUS_DEPLOY_FAIL, 85),
    DEPLOY_PERCENT_DEPLOY_OK(BaseConstantCode.JENKINS_STATUS_DEPLOY_OK, 90),
    DEPLOY_PERCENT_CHECK_FAIL(BaseConstantCode.JENKINS_STATUS_CHECK_FAIL, 95),
    DEPLOY_PERCENT_CHECK_OK(BaseConstantCode.JENKINS_STATUS_CHECK_OK, 100);

    private Integer status;

    private Integer percent;

    DeployPercentEnum(Integer status, Integer percent) {
        this.status = status;
        this.percent = percent;
    }

    public static Integer value(Integer status) {
        Integer percent;
        // 设置执行百分比
        if (status == null) {
            return 0;
        }
        switch (status) {
            case BaseConstantCode.JENKINS_STATUS_GIT_FAIL:
                percent = DEPLOY_PERCENT_GIT_FAIL.getPercent();
                break;
            case BaseConstantCode.JENKINS_STATUS_GIT_OK:
                percent = DEPLOY_PERCENT_GIT_OK.getPercent();
                break;
            case BaseConstantCode.JENKINS_STATUS_BUILD_FAIL:
                percent = DEPLOY_PERCENT_BUILD_FAIL.getPercent();
                break;
            case BaseConstantCode.JENKINS_STATUS_BUILD_OK:
                percent = DEPLOY_PERCENT_BUILD_OK.getPercent();
                break;
            case BaseConstantCode.JENKINS_STATUS_INPUT_FAIL:
                percent = DEPLOY_PERCENT_INPUT_FAIL.getPercent();
                break;
            case BaseConstantCode.JENKINS_STATUS_INPUT_OK:
                percent = DEPLOY_PERCENT_INPUT_OK.getPercent();
                break;
            case BaseConstantCode.JENKINS_STATUS_OUTPUT_FAIL:
                percent = DEPLOY_PERCENT_OUTPUT_FAIL.getPercent();
                break;
            case BaseConstantCode.JENKINS_STATUS_OUTPUT_OK:
                percent = DEPLOY_PERCENT_OUTPUT_OK.getPercent();
                break;
            case BaseConstantCode.JENKINS_STATUS_DEPLOY_FAIL:
                percent = DEPLOY_PERCENT_DEPLOY_FAIL.getPercent();
                break;
            case BaseConstantCode.JENKINS_STATUS_DEPLOY_OK:
                percent = DEPLOY_PERCENT_DEPLOY_OK.getPercent();
                break;
            case BaseConstantCode.JENKINS_STATUS_CHECK_FAIL:
                percent = DEPLOY_PERCENT_CHECK_FAIL.getPercent();
                break;
            case BaseConstantCode.JENKINS_STATUS_CHECK_OK:
                percent = DEPLOY_PERCENT_CHECK_OK.getPercent();
                break;
            default:
                percent = 0;
                break;
        }
        return percent;
    }

    public Integer getStatus() {
        return status;
    }

    public Integer getPercent() {
        return percent;
    }
}
